package com;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.io.IOException;

public class Before {
    //开始界面： 一些提示信息，以及回车进入游戏

    int count = 0;
    Image image = null;
    MainWindow mainWindow;

    public Before(MainWindow mainWindow){
        //将开始界面和窗体进行绑定
        this.mainWindow = mainWindow;
        //在加载这个界面是，图片也加载了
        //把图片读取进来
        //image = ImageIO.read(this.getClass().getClassLoader().getResourceAsStream("images/icon.png"));
        image = ImageIOUtils.getImage(this,"images/icon.png");
    }

    public void draw(Graphics graphics) {
        count++;
        //将图片画出来
        graphics.drawImage(image,150,50,null);
        graphics.setColor(Color.RED);
        graphics.setFont(new Font("楷体",Font.BOLD,30));
        if(count<=10){
            graphics.drawString("游戏开始>>",300,800);
        }else if(count<=20){
            graphics.drawString("游戏开始  >>",300,800);
        }else{
            graphics.drawString("游戏开始    >>",300,800);
            if(count>=30){
                count = 0;
            }
        }
    }

    public void keyPressed(KeyEvent e) {
        //判断按下的是不是回车键，如果是回车，进入游戏界面
        int keyCode = e.getKeyCode();
        if(keyCode == KeyEvent.VK_ENTER){
            System.out.println("进入游戏界面");
            //实则改变状态值
            //需要修改mainWindow的status的值
            //需要mainWindow的实例对象
            this.mainWindow.status = 1;
        }
    }

    public void keyReleased(KeyEvent e) {
    }
}
